package com.bokesoft.yes.mid.auth;

import com.bokesoft.yes.mid.auth.cache.Counter;
import com.bokesoft.yes.mid.auth.cache.SessionInfo;
import com.bokesoft.yes.mid.base.MidVE;
import com.bokesoft.yes.tools.util.ReflectHelper;
import com.bokesoft.yigo.common.util.TypeConvertor;
import com.bokesoft.yigo.meta.setting.MetaSession;
import com.bokesoft.yigo.meta.setting.MetaSessionPara;
import com.bokesoft.yigo.meta.setting.MetaSetting;
import com.bokesoft.yigo.mid.base.DefaultContext;
import com.bokesoft.yigo.mid.base.LoginInfo;
import com.bokesoft.yigo.mid.service.IServiceProcess;
import com.bokesoft.yigo.mid.session.ISessionInfo;
import com.bokesoft.yigo.mid.session.ISessionInfoMap;
import com.bokesoft.yigo.mid.session.SessionInfoProviderHolder;
import com.bokesoft.yigo.struct.env.Env;
import java.util.Iterator;
import java.util.Map;

public class LoginImpl {
	private LoginInfo loginInfo = null;

	public LoginImpl(LoginInfo var1) {
		this.loginInfo = var1;
	}

	public void doLoginImpl(DefaultContext var1, SessionInfo var2) throws Throwable {
//		n var3;
//		n var5;
//		(var5 = var3 = new n(this)).a = new t(var5.a);
//		if (!((MidVE) var1.getVE()).isAuthenticate() && Counter.count != 0L && Counter.passed) {
//			if (Counter.count % 10000L == 0L) {
//				var3.a(var1);
//			}
//		} else {
//			var3.a(var1);
//		}

		++Counter.count;
		ISessionInfoMap var12 = SessionInfoProviderHolder.getProvider(this.loginInfo.getMode()).getSessionInfoMap();
		MidVE var4 = var1.getVE();
		MetaSetting setting = var1.getVE().getMetaFactory().getSetting();
		Env var6;
		String var7 = (var6 = var4.getEnv()).getClientID();
		ISessionInfo var8;
		if ((var8 = var12.get(var7)) != null && var8.isGuestLogin()) {
			var12.remove(var7);
		}

		var6.setUserID(var2.getOperatorID());
		var6.setSessionParas(this.loginInfo.getParas());
		var6.setUserCode(this.loginInfo.getUser());
		var6.setRoleIDList(var2.getRoleIDList());
		MetaSession mataSession;
		if (setting != null) {
			mataSession = setting.getSession();
			Map var9 = this.loginInfo.getParas();
			if (mataSession != null && var9 != null) {
				if (mataSession.isSessionParaAsCluster()) {
					Object var16;
					if ((var16 = var9.get(mataSession.getSessionParaKey())) != null) {
						var6.setClusterid(TypeConvertor.toLong(var16));
					}
				} else {
					Iterator var17 = mataSession.iterator();

					while (var17.hasNext()) {
						MetaSessionPara var10;
						Object var11;
						if ((var10 = (MetaSessionPara) var17.next()).isAsCluster()
								&& (var11 = var9.get(var10.getParaKey())) != null) {
							var6.setClusterid(TypeConvertor.toLong(var11));
						}
					}
				}
			}
		}

		String sessionParaProcess;
		if (setting != null && (mataSession = setting.getSession()) != null && (sessionParaProcess = mataSession.getSessionParaProcess()) != null
				&& !sessionParaProcess.isEmpty()) {
			String[] sessionParaProcesses;
			int var14 = (sessionParaProcesses = sessionParaProcess.split(";")).length;

			for (int var19 = 0; var19 < var14; ++var19) {
				IServiceProcess var22;
				if (!(sessionParaProcess = sessionParaProcesses[var19]).isEmpty()
						&& (var22 = (IServiceProcess) ReflectHelper.newInstance(var4, sessionParaProcess)) != null) {
					var22.process(var1);
				}
			}
		}

		Map var21 = var6.getSessionParas();
		var2.setSessionParas(var21);
		Long var20 = var6.getClusterid();
		var2.setClusterID(var20);
		var12.put(var7, var2);
	}
}